package year2019.month12;

public class ReverseStr {

    public static void main(String[] args){
        StringBuilder sbu = new StringBuilder();
        sbu.append("0123456789");
        for (int t=0; t<1000000; t++){
            sbu.append("hesuthtuhrtyujtydijdtyjudtyhsegawgiuouipnvczsqaweqtruyuoplhmnsbvdgrtjhxrgsggegrthrsthestrhfmy");
        }
        sbu.append("9876543210");

        String str = sbu.toString();
        int count = str.length();


        long start1 = System.currentTimeMillis();
        char[] reverseChars = str.toCharArray();
        int n = count - 1;
        for (int j = (n-1) >> 1; j >= 0; j--) {
            int k = n - j;
            char cj = reverseChars[j];
            char ck = reverseChars[k];
            reverseChars[j] = ck;
            reverseChars[k] = cj;
        }
        long end1 = System.currentTimeMillis();
        System.out.println(String.valueOf(reverseChars).length());

        long start2 = System.currentTimeMillis();
        char[] oldChars = str.toCharArray();
        char[] newChars = new char[count];
        for (int i=0, k=count-1; k>=0; i++, k--){
            newChars[i] = oldChars[k];
        }
        long end2 = System.currentTimeMillis();
        System.out.println(String.valueOf(newChars).length());

        System.out.println((end1-start1));
        System.out.println((end2-start2));

    }

}
